﻿Imports System.Data.OleDb
Imports System.Data.OracleClient
Imports System.IO
Imports ccapps.persistent.FinancialDebtCollection

Public Class FinancialOverviewDebtCollection
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("user") = "" Or Session("user") Is Nothing Then
            ' Response.Redirect("../../login.aspx")
            Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()
        End If
    End Sub


    Protected Sub SMSISDN_Click(sender As Object, e As EventArgs) Handles SMSISDN.Click

        Try
            TxtCoid.Text = ""
            ErrorMes.Text = ""
            TxtCustcode.Text = ""
            LblCustomer.Text = ""
            LblCurBalance.Text = ""
            LblTotal1.Text = ""
            LblPrevBalance2.Text = ""
            LblLastBillOn.Text = ""
            LblUnBill.Text = ""
            grid.Visible = False

            If Not TxtMsisdn.Text.Length = 10 Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanı 10 Karakter İçermelidir.');</script>")
            Else

                If TxtMsisdn.Text = "" Then
                    Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanın Girilmesi Zorunludur.');</script>")
                Else
                    Dim dt As DataTable = getcustomerInfoFromMSISDN(TxtMsisdn.Text)
                    If dt.Rows.Count > 0 Then

                        LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                        LblCurBalance.Text = dt.Rows(0)("CURBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblUnBill.Text = dt.Rows(0)("UNBILL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblTotal1.Text = dt.Rows(0)("TOTAL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblLastBillOn.Text = String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("LAST_BILLED_DATE")))
                        LblPrevBalance2.Text = dt.Rows(0)("PREVBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblCsid.Text = dt.Rows(0)("CSID").ToString()
                        Dim now As DateTime = DateTime.Now
                        txtDate.Text = "12/12/" + (now.Year() - 1).ToString()
                        Dim gun As String = ""
                        Dim gun2 As String = ""

                        If now.Month().ToString().Length = 1 Then
                            gun = "0" + now.Month().ToString()
                        Else
                            gun = now.Month().ToString()
                        End If

                        If now.Day().ToString().Length = 1 Then
                            gun2 = "0" + now.Day().ToString()
                        Else
                            gun2 = now.Day().ToString()
                        End If


                        txtDate2.Text = gun2 + "/" + gun + "/" + now.Year().ToString()
                        confirmTable.Visible = True

                    Else
                        ErrorMes.Text = "Girmiş Olduğunuz MSISDN'e Ait Veri Bulunamamıştır"

                    End If
                End If
            End If

        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try


    End Sub

    Protected Sub SCustCode_Click(sender As Object, e As EventArgs) Handles SCustCode.Click


        Try
            TxtCoid.Text = ""
            ErrorMes.Text = ""
            TxtMsisdn.Text = ""
            LblCustomer.Text = ""
            LblCurBalance.Text = ""
            LblTotal1.Text = ""
            LblPrevBalance2.Text = ""
            LblLastBillOn.Text = ""
            LblUnBill.Text = ""
            grid.Visible = False

            If TxtCustcode.Text = "" Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('CustCode Alanın Girilmesi Zorunludur.');</script>")
            Else
                Dim dt As DataTable = getcustomerInfoFromCustcode(TxtCustcode.Text)
                If dt.Rows.Count > 0 Then
                    'Table2.Visible = True
                    LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                    LblCurBalance.Text = dt.Rows(0)("CURBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblUnBill.Text = dt.Rows(0)("UNBILL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblTotal1.Text = dt.Rows(0)("TOTAL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblLastBillOn.Text = String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("LAST_BILLED_DATE")))
                    LblPrevBalance2.Text = dt.Rows(0)("PREVBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblCsid.Text = dt.Rows(0)("CSID").ToString()
                    Dim now As DateTime = DateTime.Now
                    txtDate.Text = "12/12/" + (now.Year() - 1).ToString()
                    Dim gun As String = ""
                    Dim gun2 As String = ""

                    If now.Month().ToString().Length = 1 Then
                        gun = "0" + now.Month().ToString()
                    Else
                        gun = now.Month().ToString()
                    End If

                    If now.Day().ToString().Length = 1 Then
                        gun2 = "0" + now.Day().ToString()
                    Else
                        gun2 = now.Day().ToString()
                    End If

                    txtDate2.Text = gun2 + "/" + gun + "/" + now.Year().ToString()
                    confirmTable.Visible = True

                Else
                    ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE'a Ait Veri Bulunamamıştır"

                End If


            End If

        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try

    End Sub

    Protected Sub SCOID_Click(sender As Object, e As EventArgs) Handles SCOID.Click

        Try
            TxtCustcode.Text = ""
            ErrorMes.Text = ""
            TxtMsisdn.Text = ""
            LblCustomer.Text = ""
            LblCurBalance.Text = ""
            LblTotal1.Text = ""
            LblPrevBalance2.Text = ""
            LblLastBillOn.Text = ""
            LblUnBill.Text = ""
            grid.Visible = False

            If TxtCoid.Text = "" Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('COID Alanın Girilmesi Zorunludur.');</script>")
            Else
                Dim dt As DataTable = getcustomerInfoFromCOID(TxtCoid.Text)
                If dt.Rows.Count > 0 Then
                    'Table2.Visible = True
                    confirmTable.Visible = True
                    LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                    LblCurBalance.Text = dt.Rows(0)("CURBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblUnBill.Text = dt.Rows(0)("UNBILL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblTotal1.Text = dt.Rows(0)("TOTAL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblLastBillOn.Text = String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("LAST_BILLED_DATE")))
                    LblPrevBalance2.Text = dt.Rows(0)("PREVBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblCsid.Text = dt.Rows(0)("CSID").ToString()
                    Dim now As DateTime = DateTime.Now
                    txtDate.Text = "12/12/" + (now.Year() - 1).ToString()
                    Dim gun As String = ""
                    Dim gun2 As String = ""

                    If now.Month().ToString().Length = 1 Then
                        gun = "0" + now.Month().ToString()
                    Else
                        gun = now.Month().ToString()
                    End If

                    If now.Day().ToString().Length = 1 Then
                        gun2 = "0" + now.Day().ToString()
                    Else
                        gun2 = now.Day().ToString()
                    End If

                    txtDate2.Text = gun2 + "/" + gun + "/" + now.Year().ToString()

                Else
                    ErrorMes.Text = "Girmiş Olduğunuz COID'ye Ait Veri Bulunamamıştır"

                End If
                'DataGrid5.Items(4).Cells(3).Visible = False


            End If
        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try

    End Sub


    Protected Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        Try
            Dim bilgiler() As String = txtDate.Text.Split("/")
            Label26.Text = ""
            For Each satir As String In bilgiler
                Label26.Text += satir
            Next



            Dim bilgiler2() As String = txtDate2.Text.Split("/")
            Label27.Text = ""
            For Each satir2 As String In bilgiler2
                Label27.Text += satir2
            Next
            Dim pin_valid_status As Integer = 2
            If txtDate.Text = "" Then
                pin_valid_status = 1
            End If
            Dim valid_from As String = Label26.Text
            Dim valid_until As String = Label27.Text
            Dim dt As DataTable = DisplayDebtCollection(Convert.ToInt32(LblCsid.Text), Label26.Text, Label27.Text, pin_valid_status)
            DataGrid5.DataSource = dt
            DataGrid5.DataBind()
            grid.Visible = True
        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try
        


    End Sub
End Class